# -*- encoding:utf-8 -*-

from taobao.TaobaoRestClient import TaobaoRestClient
from taobao.parser.json.ObjectJsonParser import ObjectJsonParser
from taobao.parser.json.ObjectListJsonParser import ObjectListJsonParser

from taobao.model.Item import Item
from taobao.model.User import User
from taobao.model.ItemSearch import ItemSearch

from taobao.response.ItemGetResponse import ItemGetResponse
from taobao.response.ItemsGetResponse import ItemsGetResponse
from taobao.response.ItemsSearchResponse import ItemsSearchResponse
from taobao.response.UserGetResponse import UserGetResponse

class TaobaoJsonRestClient(TaobaoRestClient):
    """Taobao REST Client"""

    def __init__(self, serverUrl, appKey, appSecret):
        self.client = TaobaoRestClient(serverUrl, appKey, appSecret)

    def ItemGet(self, request):
        """taobao.item.get"""
        parser = ObjectJsonParser(Item())
        response = self.client.execute(request, parser)
        # compatible with TOP JAVA SDK, always return specific TaobaoResponse
        return ItemGetResponse(response)

    def ItemsGet(self, request):
        """taobao.items.get"""
        parser = ObjectListJsonParser(Item())
        response = self.client.execute(request, parser)
        # compatible with TOP JAVA SDK, always return specific TaobaoResponse
        return ItemsGetResponse(response)

    def ItemsSearch(self, request):
        """taobao.items.get"""
        parser = ObjectListJsonParser(ItemSearch())
        response = self.client.execute(request, parser)
        # compatible with TOP JAVA SDK, always return specific TaobaoResponse
        return ItemsSearchResponse(response)

    def UserGet(self, request):
        """taobao.user.get"""
        parser = ObjectJsonParser(User())
        response = self.client.execute(request, parser)
        # compatible with TOP JAVA SDK, always return specific TaobaoResponse
        return UserGetResponse(response)
